<template>
  <div class="Hotsearch">
    <div class="search_box">
      <div class="hot_search">
        <h3>热门搜索</h3>
        <ul class="hot_ul">
          <li class="hot_li" v-for="item in hotData" :key="item.wordid" @click="hotStr(item)">{{item.keyword}}</li>
        </ul>
      </div>
      <div class="history_search hot_search">
        <h3>历史搜索</h3>
        <ul class="history_ul hot_ul">
          <li class="history_li hot_li" v-for="item in historyData" :key="item" @click="historyStr(item)">{{item}}</li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import { getHotword } from '@/api/search'
export default {
  data() {
    return {
      hotData: [],
      historyData: this.$store.state.search.searchVal // vuex历史搜索数据
    }
  },
  created() {
    this.getHotword()
  },
  methods: {
    // 热门搜索接口
    async getHotword() {
      const res = await getHotword()
      this.hotData = res.data.data
    },
    // 点击热门文字
    hotStr(val) {
      this.$router.push('/search/' + val.keyword)
    },
    // 点击历史文字
    historyStr(val) {
      this.$router.push('/search/' + val)
    }
  }
}
</script>
<style lang="scss" scoped>
.Hotsearch{
  padding: 10px;
  h3{
    color: red;
  }
  .hot_ul{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .hot_li{
      text-align: center;
      width: 29%;
      background: #ccc;
      border-radius: 50%;
      margin-bottom: 10px;
    }
  }
}
</style>